/* File name: BufferedFPGALoopBack.c

	04Dec2007 .. initial version .. KMetzger

*/

#include<stdio.h>
#include<math.h>
#include "C5510.h"


#define xsize 352 
#define ysize 288

//#include "detection.h"
//#include "im2a.h"
//#include "control.h"
//#include "thresh.h"

#define HALF_FRAME_SIZE 25344
#define FRAME_SIZE 50688

#define PROCESSED_SIZE 6336

unsigned long McBSP0_slave(unsigned long Value);
void McBSP0_slave_setup(int ws);

void setup_buffered_McBSP0(void);
unsigned GetFromMcBSP0(void);
void SendToMcBSP0(unsigned);


// need two back to back to store whole array
#pragma DATA_SECTION(frame_array, "SDRAMC");
unsigned short frame_array[HALF_FRAME_SIZE];

#pragma DATA_SECTION(frame_array2, "SDRAMC");
unsigned short frame_array2[HALF_FRAME_SIZE];

#pragma DATA_SECTION(process_array, "SDRAMD");
unsigned short process_array[PROCESSED_SIZE];


// this won't work because it spans more than one page (>64 K)

//#pragma DATA_SECTION(frame_pixel_array, "SDRAMD");
//short frame_pixel_array[FRAME_SIZE*2];


void main(void)
{

	unsigned utemp;
	unsigned int i=0;
	int go = 0;
	unsigned short * frame_ptr = frame_array;
	unsigned short * process_ptr = process_array;

	McBSP0_slave_setup(16);
		
	while(1){
		utemp = McBSP0_slave((unsigned long)0x5678);
		//printf("%X\n",utemp);

		//printf("%s \n","while (1)");

		while(i<FRAME_SIZE)
		{
			utemp = McBSP0_slave(0x1234);
		
			if (go == 1 & i<FRAME_SIZE)
			{
				frame_array[i]= utemp;
				i++;
			}
			if (utemp == 65535)
			{
				go = 1;
			}	
		}
		//printf("%s \n","entering detection");
		detection(frame_ptr, process_ptr);

	}
}





